$(document).ready(function() {
	var citydata = returnCitySN;
	console.log(citydata.cname);
	$("#citytext").text(citydata.cname);
	//返回对象Object {cip: "122.70.200.146", cid: "110000", cname: "北京市"}
	$("#today").text(getCurrentDate(1));
	light();
	function index() {
		$('.light').css('opacity', '0.1'); //默认值
		setTimeout("$('.light').css('opacity','0.3')", 50); //第一次闪烁
		setTimeout("$('.light').css('opacity','0.5')", 100); //第二次闪烁
		setTimeout("$('.light').css('opacity','0.7')", 150); //第3次闪烁
		setTimeout("$('.light').css('opacity','0.9')", 200); //第4次闪烁
		setTimeout("$('.light').css('opacity','0.7')", 250); //第5次闪烁
		setTimeout("$('.light').css('opacity','0.5')", 300); //第6次闪烁
		setTimeout("$('.light').css('opacity','0.3')", 350); //第7次闪烁
		setTimeout("$('.light').css('opacity','0.1')", 400); //第8次闪烁
	};
	window.setInterval(index, 400); //让index 多久循环一次
	
});

/**
 *获取当前时间
 *format=1精确到天
 *format=2精确到分
 */
function getCurrentDate(format) {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth(); //得到月份
	var date = now.getDate(); //得到日期
	var day = now.getDay(); //得到周几
	var hour = now.getHours(); //得到小时
	var minu = now.getMinutes(); //得到分钟
	var sec = now.getSeconds(); //得到秒
	month = month + 1;
	if(month < 10) month = "0" + month;
	if(date < 10) date = "0" + date;
	if(hour < 10) hour = "0" + hour;
	if(minu < 10) minu = "0" + minu;
	if(sec < 10) sec = "0" + sec;
	var time = "";
	//精确到天
	if(format == 1) {
		time = year + "-" + month + "-" + date;
	}
	//精确到分
	else if(format == 2) {
		time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
	}
	return time;
}
//百度地图API功能
function loadJScript() {
	var srcbaidu = "http://api.map.baidu.com/api?v=2.0&ak=MjBOWGRHzFaE7xiaS2vXq4fXpVy2cT7U&callback=init";
	//异步地图加载
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = srcbaidu;
	document.body.appendChild(script);
}

function init() {
	var longitude = 112.987410;
	var dimension = 28.23300;
	// 百度地图API功能
	var map = new BMap.Map("allmap1");
	var point = new BMap.Point(longitude, dimension);
	map.centerAndZoom(point, 18);
	//创建跳动logo
	var pt = new BMap.Point(longitude, dimension);
	var myIcon = new BMap.Icon("../../resources/images/zj-logo.png", new BMap.Size(80, 38));
	var marker2 = new BMap.Marker(pt, { icon: myIcon }); // 创建标注
	map.addOverlay(marker2); // 将标注添加到地图中
	marker2.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	//地图控件
	map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
	map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
	map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
	map.enableScrollWheelZoom(); //启用滚轮放大缩小

	var data_info = [
		[112.987410, 28.23280, "地址：北辰新河三角洲E7区1#-7#栋"],
	];
	for(var i = 0; i < data_info.length; i++) {
		var marker = new BMap.Marker(new BMap.Point(data_info[i][0], data_info[i][1])); // 创建标注
		var content = data_info[i][2];
		map.addOverlay(marker); // 将标注添加到地图中
		addClickHandler(content, marker);
	}

	var opts = {
		width: 250, // 信息窗口宽度
		height: 40, // 信息窗口高度
		title: '<b style="color:#1d9cdd">G层及地下室建安工程</b>', // 信息窗口标题
		enableMessage: true //设置允许信息窗发送短息
	};

	function addClickHandler(content, marker) {
		marker.addEventListener("click", function(e) {
			openInfo(content, e)
		});
	}

	function openInfo(content, e) {
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象 
		map.openInfoWindow(infoWindow, point); //开启信息窗口
	}
}

function light() {
	$(function() {
		var $this = $(".scrollNews");
		var scrollTimer;
		$this.hover(function() {
			clearInterval(scrollTimer);
		}, function() {
			scrollTimer = setInterval(function() {
				scrollNews($this);
			}, 500);
		}).trigger("mouseleave");
	});

	function scrollNews(obj) {
		var $self = obj.find("ul:first");
		var lineHeight = $self.find("li:first").width(); //获取宽度，向上滚动则需要获取高度.height()
		$self.animate({ "marginLeft": -lineHeight + "px" }, 6000, function() { //向左滚动，向上滚动则需要改为marginTop,其他方向类似，下同
			$self.css({ marginLeft: 0 }).find("li:first").appendTo($self); //appendTo能直接移动元素
		})
	}
}

window.onload = loadJScript; //异步加载地图